{% import "TopxiaWebBundle::macro.html.twig" as web_macro %}
{% import "TopxiaAdminBundle::macro.html.twig" as admin_macro %}
{% import _self as self_macro %}

{% set menu = menu|default(null) %}
{% set currentMenu = permission(menu) %}
{% set cloudSmsInfo = isOldSmsUser()|default(false) %}

<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class=""> <!--<![endif]-->
{# returns app.request.locale if available and app.request.defaultLocale if app.request.locale is not set#}
<html lang="{{ app.request.getLocale() }}">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="renderer" content="webkit">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta content="{{ csrf_token('site') }}" name="csrf-token" />
  <title>

    {% block title %}
      {{ currentMenu.name|trans }} - {{ menu|parent_permission.name|trans }} - {{ menu|parent_permission.code|parent_permission.name|trans  }}
    {% endblock %}
    {% if not setting('copyright.owned') %} | EduSoho{% endif %}
  </title>

  {% if setting('site.favicon') %}
    <link rel="icon" href="{{ asset(setting('site.favicon')) }}" type="image/x-icon" />
    <link href="{{ asset(setting('site.favicon')) }}" rel="shortcut icon" />
  {% endif %}
  
  {% block stylesheets %}
  <link href="{{ asset('assets/libs/gallery2/bootstrap/3.1.1/css/bootstrap.css') }}" rel="stylesheet" />
  <link href="{{ asset('assets/css/common.css') }}" rel="stylesheet" />
  <link href="{{ asset('bundles/topxiaadmin/css/admin.css') }}" rel="stylesheet" />
  <link href="{{ asset('bundles/topxiaadmin/css/admin_v2.css') }}" rel="stylesheet" />
  <link href="{{ asset('assets/v2/css/admin/educloud.css') }}" rel="stylesheet" />
  <link rel="stylesheet" media="screen" href="{{ asset('assets/v2/css/es-icon.css') }}" />
  {% endblock %}

  {% block javascripts %}{% endblock %}
  <!--[if lt IE 9]>
    <script src="{{ asset('assets/libs/html5shiv.js') }}"></script>
    <script src="{{ asset('assets/libs/respond.min.js') }}"></script>
  <![endif]-->
</head>
<body>
  <div class="navbar navbar-inverse navbar-fixed-top">
  {% if cloudSmsInfo %}
    <div class="alert alert-danger es-admin-alert" role="alert"><div class="text-center"><strong>您好，ES云短信发送机制升级优化，网站目前短信剩余{{cloudSmsInfo.remainCount|default(0)}}条，为保证继续使用，请开通教育云，点击 <a href="http://open.edusoho.com/cloud/access" target="_blank"> 立即开通</a></strong></div></div>
  {% endif %}
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="{{ url('admin') }}">{% if not setting('copyright.owned') %}EduSoho{% endif %}{{'管理后台'|trans}}</a>
      </div>
      <div class="navbar-collapse collapse">
        {% include 'PermissionBundle:Templates:navigation.html.twig' with {parentCode:'admin'} %}

        <ul class="nav navbar-nav navbar-right">
          <li data-url="{{path('admin_common_admin')}}">
            <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown" ><span class="glyphicon glyphicon-list admin-star"></span> {{'常用'|trans}}</a>
            <ul class="dropdown-menu shortcuts">
              {{ render(controller('TopxiaAdminBundle:CommonAdmin:commonAdmin')) }}
            </ul>
          </li>
          <li><a href="{{ path('homepage') }}"><i class="glyphicon glyphicon-home"></i> {{'回首页'|trans}}</a></li>

          <li class="dropdown">
            <a href="javascript:;" class="dropdown-toggle" data-toggle="dropdown"><i class="glyphicon glyphicon-user"></i> {{ app.user.nickname }} <span class="glyphicon glyphicon-chevron-down"></span></a>
            <ul class="dropdown-menu main-list">
              <li><a href="{{ path('logout') }}"><i class="glyphicon glyphicon-off"></i> {{'退出'|trans}}</a></li>
            </ul>
          </li>
        </ul>

      </div><!--/.navbar-collapse -->
    </div>
  </div>
  
  <div class="container {% if cloudSmsInfo %}es-admin-container-down{% endif %}">
    
    {% set notifies = plugin_update_notify() %}
    {% if not notifies is empty %}
      <div class="alert alert-warning">
        【重要】网站升级v7.2.0后，为保证正常使用，请务必及时升级插件（{{ notifies }}）至最新版！请立即升级！ <a href="{{ path('admin_app_upgrades') }}">查看详情</a>
      </div>
    {% endif %}

    {% block container %}
      <div class="row">  
        {% block content %}
          <div class="col-md-2">
            {% block sidebar %}
              {% include 'PermissionBundle:Templates:side-bar.html.twig' %}
            {% endblock %}
          </div>

          <div class="col-md-10">
            <div class="page-header clearfix">
              {% block page_flash_message %}

              {% endblock %}
              <h1 class="pull-left">
                {% block page_title %}
                  {{ currentMenu.code|parent_permission.name|trans }}
                {% endblock %}
              </h1>
              <div class="pull-right">

                {% block page_buttons %}

                  {% if currentMenu.mode|default('') == 'capsules' and capsule|default(false) %}
                    {% for m in sub_permissions(permission(capsule).code,'topBtn') %}
                      {{ self_macro.menu_link_html(_context, m, 'btn btn-success btn-sm') }}
                    {% endfor %}
                  {% else %}
                    {% for m in sub_permissions(currentMenu.code,'topBtn') %}
                      {{ self_macro.menu_link_html(_context, m, 'btn btn-success btn-sm') }}
                    {% endfor %}
                  {% endif %}
                {% endblock %}

              </div>
            </div>

            {% block content_header %}{% endblock %}
            
            {% block tabs %}{% include 'PermissionBundle:Templates:tabs.html.twig' %}{% endblock %}

            {% block capsule %}{% endblock %}

            {% block main %}{% endblock %}
          </div>

        {% endblock %}
      </div>
    {% endblock %}

  </div>

  {% block footer %}
    {{ setting('site.analytics')|raw }} 
  {% endblock %}

  {% include 'TopxiaWebBundle::script_boot.html.twig' with {script_main: asset('bundles/topxiaadmin/js/admin-app.js')} %}
  <div id="modal" class="modal" ></div>
  {% if setting('copyright.thirdCopyright') != 1 %}
    <div class="fixed-bar">
      <a href="{{path('admin_feedback')}}"  target='_blank' class="icon-question-text feedback">
        <i class="es-icon es-icon-help"></i>
        <span>{{'产品'|trans}}<br/>{{'反馈'|trans}}</span>
      </a>
    </div>
  {% endif %}
</body>
</html>

{% macro menu_link_html(_context, menu, class) %}
  <a 
  {% if class %}
    class="{{ class }}"
  {% endif %}
  {% if menu.mode|default(null) == 'modal' %}
    data-url="{{ permission_path(menu) }}"
    data-toggle="modal"
    data-target="#modal"
  {% else %}
    href="{{ permission_path(menu) }}"
  {% endif %}
  {% if menu.blank|default(false) %}
    target="blank"
  {% endif %}
  >{{ menu.name|trans }}</a>
{% endmacro %}